/*var mainStartCode ='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function initDiagPage(baseInfoJson,diseaseDiagInfoJson){
	var basePath = $("#basePath").val();
	var diagTypes = baseInfoJson['diagTypes'];//诊断类型
	
	var treatmentResults = baseInfoJson['treatmentResults'];//治疗结果
	
	
	var diseaseDiagRecords = diseaseDiagInfoJson['diseaseDiagRecords'];//诊断记录集合
	
	var count = 0;
	var otherDiagCount = 2;
	for (var i = 0; i < diseaseDiagRecords.length; i++) {
		var diseaseDiagRecord = diseaseDiagRecords[i];
		var diagTypeCode = diseaseDiagRecord.diagTypeCode;
		var diseaseDiagOriginalDesc = diseaseDiagRecord.diseaseDiagOriginalDesc;
		var diseaseDiagCode = diseaseDiagRecord.diseaseDiagCode;
		var inHospitalDiseaseStateCode = diseaseDiagRecord.inHospitalDiseaseStateCode;
		console.log(inHospitalDiseaseStateCode);
		if(diagTypeCode=='4'){
			count=0;
		}else if(diagTypeCode=='15'){
			count=1;
		}else if(diagTypeCode=='21'){
			count=15;
		}else if(diagTypeCode=='16'){
			count = otherDiagCount;
		}
		
		
		$("input[name='diseaseDiagRecords["+count+"].diseaseDiagOriginalDesc']").val(diseaseDiagOriginalDesc);
		$("input[name='diseaseDiagRecords["+count+"].inHospitalDiseaseStateCode']").val(inHospitalDiseaseStateCode);
		$("input[name='diseaseDiagRecords["+count+"].diseaseDiagCode']").val(diseaseDiagCode);
		if(diagTypeCode=='16'){
			otherDiagCount++;
		}
	}

	
	
};
*/

	
	
	
	






var mainStartCode ='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function initDiagPage(baseInfoJson,diseaseDiagInfoJson){
	var basePath = $("#basePath").val();
	
	var diagTypes = baseInfoJson['diagTypes'];//诊断类型
	
	
	
	var treatmentResults = baseInfoJson['treatmentResults'];//治疗结果
	
	
	var diseaseDiagRecords = diseaseDiagInfoJson['diseaseDiagRecords'];//诊断记录集合
	
	
	
	$(".diagTypeSelect").each(function(){
		var options = "";
		for(var index in diagTypes){
			var diagType = diagTypes[index];
	    	options+="<option value='"+diagType.uniq_code+"'>"+diagType.label+"</option>"
	    } 
       $(this).append(options);
       
	});
	
	$(".treatResultSelect").each(function(){
		var options = "";
		for(var index in treatmentResults){
			var treatmentResult = treatmentResults[index];
	    	options+="<option value='"+treatmentResult.uniq_code+"'>"+treatmentResult.label+"</option>"
	    } 
       $(this).append(options);
       
	});
	
	
	var inHospitalDiseaseStates = baseInfoJson['inHospitalDiseaseStates'];//入院疾病状况
	$("select[name$='.inHospitalDiseaseStateCode']").each(function(){
		var options = "";
		for(var index in inHospitalDiseaseStates){
			var inHospitalDiseaseState = inHospitalDiseaseStates[index];
	    	options+="<option value='"+inHospitalDiseaseState.uniq_code+"'>"+inHospitalDiseaseState.label+"</option>"
	    } 
       $(this).append(options);
       
	});
	
	
	$(".operateMark").each(function(){
		options = "<option value='0'>非手术治疗</option>";
		
		options+="<option value='1'>手术治疗</option>";
			$(this).append(options);
		
	});
	
	var count = 0;
	
	for(var index in diseaseDiagRecords){
		var diseaseDiagRecord = diseaseDiagRecords[index];
		addDiseaseDiagRecordByDiag(diseaseDiagRecord);
		
		count++;
    } 
	
	if($("#diseaseDiagTable tbody tr").length == 0){
		addDiseaseDiagRecord();
	}
	
	
};

function addDiseaseDiagRecord(){
	var basePath = $("#basePath").val();
	var diseaseDiagCountOjb = $("#diseaseDiagCount");
	var count = parseInt(diseaseDiagCountOjb.val());
	var add_content=$("#templateDiseaseDiagTr").clone();
	add_content.removeAttr("id");
	
	var diagTypeCodeOjb= add_content.find("select[name='diseaseDiagRecords[0].diagTypeCode']");
	diagTypeCodeOjb.attr("name","diseaseDiagRecords["+count+"].diagTypeCode");
	
	add_content.find("input[name='diseaseDiagRecords[0].diagTypeName']").attr("name","diseaseDiagRecords["+count+"].diagTypeName");
	add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagOriginalCode']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagOriginalCode");
	add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagOriginalDesc']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagOriginalDesc");
	add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagShow']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagShow");
	
	add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagCode']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagCode");
	add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagName']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagName");
	
	
	//add_content.find("select[name='diseaseDiagRecords[0].treatResultCode']").attr("name","diseaseDiagRecords["+count+"].treatResultCode");
	//add_content.find("input[name='diseaseDiagRecords[0].treatResultName']").attr("name","diseaseDiagRecords["+count+"].treatResultName");
	
	//add_content.find("input[name='diseaseDiagRecords[0].confirmedDateTime']").attr("name","diseaseDiagRecords["+count+"].confirmedDateTime");
	//add_content.find("input[name='diseaseDiagRecords[0].treatDayNumber']").attr("name","diseaseDiagRecords["+count+"].treatDayNumber");
	add_content.find("input[name='diseaseDiagRecords[0].diagSortIndex']").attr("name","diseaseDiagRecords["+count+"].diagSortIndex");
	add_content.find("input[name='diseaseDiagRecords[0].inHospitalDiseaseStateName']").attr("name","diseaseDiagRecords["+count+"].inHospitalDiseaseStateName");
	add_content.find("input[name='diseaseDiagRecords[0].treatResultName']").attr("name","diseaseDiagRecords["+count+"].treatResultName");
	
/*	add_content.find("select[name='diseaseDiagRecords[0].operateMarkCode']").attr("name","diseaseDiagRecords["+count+"].operateMarkCode");
	add_content.find("input[name='diseaseDiagRecords[0].operateMarkName']").attr("name","diseaseDiagRecords["+count+"].operateMarkName");
	add_content.find("input[name='diseaseDiagRecords[0].operatingLevel']").attr("name","diseaseDiagRecords["+count+"].operatingLevel");*/
	
	$.each(add_content.find(".diagTypeSelect"),function(i,item) {
		$(item).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
		
	});
	
	
	$.each(add_content.find("input[data-type='diseaseDiag']"),function(i,item) {
		$(item).autocomplete({
			source: function( request, response ) {
				var eventObj = $(this.element);
				
				var codeObjName = eventObj.attr("name").replace("Show", "Code");
				eventObj.nextAll("input[name='"+codeObjName+"']").val("");
				
				var nameObjName = eventObj.attr("name").replace("Show", "Name");
				eventObj.nextAll("input[name='"+nameObjName+"']").val("");
				
				$.ajax({
					url: basePath + "base_info/ajax_diseases_by_query_name",
					dataType: "json",
					data:{
						queryName: request.term
					},
					success: function( data ) {
					response( $.map( data, function( item ) {
						return {
							label:item.uniq_code+'['+item.label+']',
							uniq_code:item.uniq_code,
							uniq_name:item.label
						}
					}));
				}
			});
			},
			minLength: 2,
			select: function( event, ui ) {
				var eventObj = $(this);
				var item = ui.item;
				var codeObjName = eventObj.attr("name").replace("Show", "Code");
				eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
				
				var nameObjName = eventObj.attr("name").replace("Show", "Name");
				eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name);
			},search: function( event, ui ) {
				var eventObj = $(this);
				var codeObjName = eventObj.attr("name").replace("Show", "Code");
				eventObj.nextAll("input[name='"+codeObjName+"']").val("");
				
				var nameObjName = eventObj.attr("name").replace("Show", "Name");
				eventObj.nextAll("input[name='"+nameObjName+"']").val("");
				
			}
		});
	});
	
	$.each(add_content.find(".diseaseDiagSearchInput"),function(i,item) {
		$(item).autocomplete({
			source: function( request, response ) {
				var eventObj = $(this.element);
				
				var codeObjName = eventObj.attr("name").replace("Name", "Code");
				eventObj.next("input[name='"+codeObjName+"']").val("");
				 eventObj.next("input[data-code='search_input1']").val(""); 
				$.ajax({
					url: basePath + "base_info/ajax_diseases_by_query_name",
					dataType: "json",
					data:{
						queryName: request.term
					},
					success: function( data ) {
					response( $.map( data, function( item ) {
						return {
							label:item.label,
							uniq_code:item.uniq_code
						}
					}));
				}
			});
			},
			minLength: 2,
			select: function( event, ui ) {
				var eventObj = $(this);
				var item = ui.item;
				var codeObjName = eventObj.attr("name").replace("Name", "Code");
				
				eventObj.next("input[name='"+codeObjName+"']").val(item.uniq_code);
				 eventObj.next("input[data-code='search_input1']").val(item.code); 
			},search: function( event, ui ) {
				 eventObj.next("input[data-code='search_input1']").val(""); 
				var eventObj = $(this);
				var codeObjName = eventObj.attr("name").replace("Name", "Code");
				eventObj.next("input[name='"+codeObjName+"']").val("");
			}
		});
	});
	
	$.each(add_content.find(".treatResultSelect"),function(i,item) {
		$(item).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
		
	});
	
	$.each(add_content.find(".operateMark"),function(i,item) {
		$(item).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
		
	});
	
	$.each(add_content.find("select[name$='.inHospitalDiseaseStateCode']"),function(i,item) {
		$(item).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
		
	});
	
	$("#diseaseDiagTable tbody").append(add_content);
	diseaseDiagCountOjb.val(count +1);
}

function addDiseaseDiagRecordByDiag(diseaseDiagRecord){
	
	var diagTypeCode =diseaseDiagRecord.diagTypeCode;	
	
	var basePath = $("#basePath").val();
	var diseaseDiagCountOjb = $("#diseaseDiagCount");
	var count = parseInt(diseaseDiagCountOjb.val());
	var add_content=$("#templateDiseaseDiagTr").clone();
	add_content.removeAttr("id");
	
	var diagTypeCodeOjb= add_content.find("select[name='diseaseDiagRecords[0].diagTypeCode']");
	diagTypeCodeOjb.attr("name","diseaseDiagRecords["+count+"].diagTypeCode");
	
	
	//疾病描述为空进行提示
	if(diseaseDiagRecord.diseaseDiagOriginalDescValid){
		add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagOriginalDesc']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagOriginalDesc").val(diseaseDiagRecord.diseaseDiagOriginalDesc).attr("data-content",diseaseDiagRecord.diseaseDiagOriginalDescValid)
		.css({"border":"1px solid red"}).popover({placement:'right'});
	}else{
		add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagOriginalDesc']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagOriginalDesc").val(diseaseDiagRecord.diseaseDiagOriginalDesc);
	}
	add_content.find("input[name='diseaseDiagRecords[0].diagTypeName']").attr("name","diseaseDiagRecords["+count+"].diagTypeName");
	
	//疾病编码有问题时进行提示
	if(diseaseDiagRecord.diseaseDiagCodeValid){
		add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagCode']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagCode").val(diseaseDiagRecord.diseaseDiagCode).attr("data-content",diseaseDiagRecord.diseaseDiagCodeValid)
		.css({"border":"1px solid red"}).popover({placement:'right'});
	}else{
		add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagCode']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagCode").val(diseaseDiagRecord.diseaseDiagCode);
	}
	add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagName']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagName").val(diseaseDiagRecord.diseaseDiagName);
	add_content.find("input[name='diseaseDiagRecords[0].diseaseDiagOriginalCode']").attr("name","diseaseDiagRecords["+count+"].diseaseDiagOriginalCode").val(diseaseDiagRecord.diseaseDiagOriginalCode);

	if(diseaseDiagRecord.inHospitalDiseaseStateNameValid){
		add_content.find("input[name='diseaseDiagRecords[0].inHospitalDiseaseStateName']").attr("name","diseaseDiagRecords["+count+"].inHospitalDiseaseStateName").val(diseaseDiagRecord.inHospitalDiseaseStateName).attr("data-content",diseaseDiagRecord.inHospitalDiseaseStateNameValid)
		.css({"border":"1px solid red"}).popover({placement:'left'});
		
	}else{
		add_content.find("input[name='diseaseDiagRecords[0].inHospitalDiseaseStateName']").attr("name","diseaseDiagRecords["+count+"].inHospitalDiseaseStateName").val(diseaseDiagRecord.inHospitalDiseaseStateName);
		
	}
	
	if(diseaseDiagRecord.treatResultNameValid){
		add_content.find("input[name='diseaseDiagRecords[0].treatResultName']").attr("name","diseaseDiagRecords["+count+"].treatResultName").val(diseaseDiagRecord.treatResultName).attr("data-content",diseaseDiagRecord.treatResultNameValid)
		.css({"border":"1px solid red"}).popover({placement:'left'});
		
	}else{
		add_content.find("input[name='diseaseDiagRecords[0].treatResultName']").attr("name","diseaseDiagRecords["+count+"].treatResultName").val(diseaseDiagRecord.treatResultName);
		
	}
	
	
	
	
	
	
	

	
	add_content.find("select[name='diseaseDiagRecords[0].treatResultCode']").attr("name","diseaseDiagRecords["+count+"].treatResultCode");

	add_content.find("input[name='diseaseDiagRecords[0].confirmedDateTime']").attr("name","diseaseDiagRecords["+count+"].confirmedDateTime").val(diseaseDiagRecord.confirmedDateTime);
	add_content.find("input[name='diseaseDiagRecords[0].treatDayNumber']").attr("name","diseaseDiagRecords["+count+"].treatDayNumber").val(diseaseDiagRecord.treatDayNumber);
	add_content.find("input[name='diseaseDiagRecords[0].diagSortIndex']").attr("name","diseaseDiagRecords["+count+"].diagSortIndex").val(diseaseDiagRecord.diagSortIndex);
	


	add_content.find("select[name='diseaseDiagRecords[0].operateMarkCode']").attr("name","diseaseDiagRecords["+count+"].operateMarkCode");
	add_content.find("input[name='diseaseDiagRecords[0].operateMarkName']").attr("name","diseaseDiagRecords["+count+"].operateMarkName");
	
	add_content.find("input[name='diseaseDiagRecords[0].operatingLevel']").attr("name","diseaseDiagRecords["+count+"].operatingLevel").val(diseaseDiagRecord.operatingLevel);
	
	
	
	$.each(add_content.find(".diagTypeSelect"),function(i,item) {
		$(item).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
		if(diseaseDiagRecord.diagTypeCode){
			
			var selectOption = $(item).find("option[value='"+diseaseDiagRecord.diagTypeCode+"']")
			if(selectOption.length > 0){
				selectOption.attr("selected",true);
			}else{
				$(item).append("<option selected='selected' value='"+diseaseDiagRecord.diagTypeCode+"'>"+diseaseDiagRecord.diagTypeName+"</option>");
			}
			
		}
		;
		var o =$(item).next("input[name='"+$(item).attr("name").replace("Code", "Name")+"']");
		$(item).next("input[name='"+$(item).attr("name").replace("Code", "Name")+"']").val(diseaseDiagRecord.diagTypeName);
	});
	
	
/*	
	if(diseaseDiagRecord.diseaseDiagCode){
		add_content.find("input[name$='diseaseDiagShow']").val(diseaseDiagRecord.diseaseDiagCode+'['+diseaseDiagRecord.diseaseDiagName+']');
		
	}*/
	
	$.each(add_content.find("input[data-type='diseaseDiag']"),function(i,item) {
		$(item).autocomplete({
			source: function( request, response ) {
				var eventObj = $(this.element);
				
				
				//var codeObjName = eventObj.attr("name").replace("Show", "Code");
				//eventObj.nextAll("input[name='"+codeObjName+"']").val("");
				
				//var nameObjName = eventObj.attr("name").replace("Show", "Name");
				//eventObj.nextAll("input[name='"+nameObjName+"']").val("");
				
				var codeObjName = eventObj.attr("name").replace("Code","Name");
				//清空选择框
				//eventObj.val("");
				$("input[name='"+codeObjName+"']").val("");
				
				
				$.ajax({
					url: basePath + "base_info/ajax_diseases_by_query_name",
					dataType: "json",
					data:{
						queryName: request.term
					},
					success: function( data ) {
						if(data.length==1){
							$("input[name='"+codeObjName+"']").val("").val(data[0].label);
							eventObj.val("").val(data[0].uniq_code);
							return;
							
						}
					response( $.map( data, function( item ) {
				
						return {
							label:item.uniq_code,
							uniq_name:item.label,
							uniq_code:item.uniq_code
						}
					}));
				}
			});
			},
			minLength: 2,
			select: function( event, ui ) {
				var eventObj = $(this);
				var item = ui.item;
				item.label=item.uniq_code;
				var codeObjName = eventObj.attr("name").replace("Code", "Name");
				//$("input[name='"+codeObjName+"']").val(item.uniq_name);
				$("input[name='"+codeObjName+"']").val(item.uniq_name);
				
		
				/*var codeObjName = eventObj.attr("name").replace("Show", "Code");
				eventObj.nextAll("input[name='"+codeObjName+"']").val(item.uniq_code);
				
				var nameObjName = eventObj.attr("name").replace("Show", "Name");
				eventObj.nextAll("input[name='"+nameObjName+"']").val(item.uniq_name)*/;
			},search: function( event, ui ) {
				var eventObj = $(this);
				//eventObj.val("");
				var codeObjName = eventObj.attr("name").replace("Code", "Name");
				eventObj.nextAll("input[name='"+codeObjName+"']").val("");
				$("input[name='"+codeObjName+"']").val("");
				
			
				
				/*var nameObjName = eventObj.attr("name").replace("Show", "Name");
				eventObj.nextAll("input[name='"+nameObjName+"']").val("");*/
				
			}
		}).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
	  	      return $( "<li>" )
		        .append( "<a>" + item.uniq_name+"-"+item.uniq_code +"</a>" )
		        .appendTo( ul );
		    };
	});
	
	$.each(add_content.find(".diseaseDiagSearchInput"),function(i,item) {
		$(item).autocomplete({
			source: function( request, response ) {
				var eventObj = $(this.element);
				
				var codeObjName = eventObj.attr("name").replace("Name", "Code");
				eventObj.next("input[name='"+codeObjName+"']").val("");
				$.ajax({
					url: basePath + "base_info/ajax_diseases_by_query_name",
					dataType: "json",
					data:{
						queryName: request.term
					},
					success: function( data ) {
					response( $.map( data, function( item ) {
						return {
							label:item.label,
							uniq_code:item.uniq_code
						}
					}));
				}
			});
			},
			minLength: 1,
			select: function( event, ui ) {
				var eventObj = $(this);
				var item = ui.item;
				var codeObjName = eventObj.attr("name").replace("Name", "Code");
				eventObj.next("input[name='"+codeObjName+"']").val(item.uniq_code);
			},search: function( event, ui ) {
				var eventObj = $(this);
				var codeObjName = eventObj.attr("name").replace("Name", "Code");
				eventObj.next("input[name='"+codeObjName+"']").val("");
			}
		});
	});
	
	$.each(add_content.find(".treatResultSelect"),function(i,item) {
		$(item).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
		if(diseaseDiagRecord.treatResultCode){
			
			var selectOption = $(item).find("option[value='"+diseaseDiagRecord.treatResultCode+"']")
			if(selectOption.length > 0){
				selectOption.attr("selected",true);
			}else{
				$(item).append("<option selected='selected' value='"+diseaseDiagRecord.treatResultCode+"'>"+diseaseDiagRecord.treatResultName+"</option>");
			}
			
		}
		;
		$(item).next("input[name='"+$(item).attr("name").replace("Code", "Name")+"']").val(diseaseDiagRecord.treatResultName);
	});
	
	$.each(add_content.find("select[name$='.inHospitalDiseaseStateCode']"),function(i,item) {
		$(item).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
		if(diseaseDiagRecord.inHospitalDiseaseStateCode){
			
			var selectOption = $(item).find("option[value='"+diseaseDiagRecord.inHospitalDiseaseStateCode+"']")
			if(selectOption.length > 0){
				selectOption.attr("selected",true);
			}else{
				$(item).append("<option selected='selected' value='"+diseaseDiagRecord.inHospitalDiseaseStateCode+"'>"+diseaseDiagRecord.inHospitalDiseaseStateName+"</option>");
			}
			
		};
		if(diseaseDiagRecord.inHospitalDiseaseStateCode){
			$(item).next("input[name='"+$(item).attr("name").replace("Code", "Name")+"']").val(diseaseDiagRecord.inHospitalDiseaseStateName);
		}
		
	
		
		
		
		
	});
	$.each(add_content.find(".operateMark"),function(i,item) {
		$(item).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   	});
		if(diseaseDiagRecord.operateMarkCode){
			
				var selectOption = $(item).find("option[value='"+diseaseDiagRecord.operateMarkCode+"']")
				if(selectOption.length > 0){
					selectOption.attr("selected",true);
				}else{
					$(item).append("<option selected='selected' value='"+diseaseDiagRecord.operateMarkCode+"'>"+diseaseDiagRecord.operateMarkName+"</option>");
				}
				
			};
			$(item).next("input[name='"+$(item).attr("name").replace("Code", "Name")+"']").val(diseaseDiagRecord.operateMarkName);
		});
	if("1"== diseaseDiagRecord.operatingLevel){
		$.each(add_content.find("a"),function(i,item) {
			$(item).css({  
                visibility: 'hidden',  
            });  
			
		});
		
	}
	$("#diseaseDiagTable tbody").append(add_content);
	diseaseDiagCountOjb.val(count +1);
	
}
function deleteDiseaseDiagRecord(obj){
	$(obj).parent().parent().remove();
}





